/* eslint-disable @typescript-eslint/no-unused-vars */
import { ElMessage, ElNotification } from "element-plus";
import router from "@/routers";
import { LOGIN_URL } from "@/config/config";
import { Router } from "vue-router";
import { useRouter, useRoute } from "vue-router";
import i18n from "@/languages/index";

const { t } = i18n.global;
/**
 * @description: 校验网络请求状态码
 * @param {Number} status
 * @return boolean
 */
export const checkStatus = (status?: number): boolean => {
	let ok = true;
	switch (status) {
		case 400:
			ok = false;
			ElMessage.error(t("api.errmsg.400"));
			break;
		case 401:
			ok = false;
			// ElMessage.error("登录失效！请您重新登录");
			ElNotification.warning({
				title: "登录失效",
				message: "用户登录状态已失效，请重新登录"
			});
			// router.replace(LOGIN_URL);
			const param = {} as any;
			if (router.currentRoute.value.fullPath != "/") {
				param.redirect = encodeURIComponent(router.currentRoute.value.fullPath);
			}
			router.replace({ path: LOGIN_URL, query: param });
			// window.location.href = LOGIN_URL;
			break;
		case 403:
			ok = false;
			ElMessage.error(t("api.errmsg.403"));
			break;
		case 404:
			ok = false;
			ElMessage.error(t("api.errmsg.404"));
			break;
		case 405:
			ok = false;
			ElMessage.error(t("api.errmsg.405"));
			break;
		case 408:
			ok = false;
			ElMessage.error(t("api.errmsg.408"));
			break;
		case 500:
			ok = false;
			ElMessage.error(t("api.errmsg.500"));
			break;
		case 502:
			ok = false;
			ElMessage.error(t("api.errmsg.502"));
			break;
		case 503:
			ok = false;
			ElMessage.error(t("api.errmsg.503"));
			break;
		case 504:
			ok = false;
			ElMessage.error(t("api.errmsg.504"));
			break;
		default:
			ok = false;
			ElMessage.error(t("api.errmsg.default"));
	}
	return ok;
};
